/**
 * 
 */
package userController;

import java.io.IOException;
import java.sql.SQLException;

import rentReturnController.RentController;
import rentReturnController.ReportController;
import rentReturnController.ReturnController;
import reservationController.ReservationController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import vehicleController.PurchaseVehicleController;
import vehicleController.SellVehicleController;

/**
 * @author Yokesh Kumar
 *
 */
public class ManagerController {

	@FXML
	private Label userName;
	
	@FXML
	private Stage managerStage;
	
	@FXML
	public String customerPhNo;
	
	@FXML
	private StackPane managerStackPane;
	
	
	/**
	 * @param managerStackPane the managerStackPane to set
	 */
	public void setManagerStackPane(Node node) {
		managerStackPane.getChildren().setAll(node);
	}
	

	

	public void setName(String name){
		//userName = new Label(name);
		userName.setText(name);
	}
	
	public void SetStage(Stage Stage){
		this.managerStage=Stage;
	}
	
	
	/**
	 * Invoke Report controller
	 * @param event
	 */
	@FXML
	public void generateReport(ActionEvent event){
		Navigator.loadStackPane(Navigator.REPORT);
	}
	
	
	/**
	 * Invoke purchase controller.fetchPurchasedVehicles
	 * @param event
	 */
	@FXML
	public void purchase(ActionEvent event){
		PurchaseVehicleController purchaseController = new PurchaseVehicleController();
		purchaseController.fetchPurchasedVehicles();
	}
	
	/**
	 * Invoke move controller
	 * @param event
	 */
	@FXML
	public void move(ActionEvent event){
		System.out.println("Invoking move");
		Navigator.loadStackPane(Navigator.MOVE_VEHICLE);
	}
	
	/**
	 * Invoke sell controller.fetchSaleVehicles
	 * @param event
	 */
	@FXML
	public void sell(ActionEvent event){
		System.out.println("sale list invoked from Manager Controller");
		SellVehicleController sellController = new SellVehicleController();
		sellController.fetchSaleVehicles();
	}
	
	/**
	 * Invoke setRate controller
	 * @param event
	 */
	@FXML
	public void setRate(ActionEvent event){
		Navigator.loadStackPane(Navigator.SET_RATE);
	}
	
	/**
	 * Invoke reservationcontroller.doReservation
	 * @param event
	 */
	@FXML
	public void doReservation(ActionEvent event){
		ReservationController rcController = new ReservationController();
		rcController.page=-1;
		rcController.makeReservation();
	}
	
	/**
	 * Invoke reservationcontroller.cancelreservation
	 * @param event
	 */
	@FXML
	public void cancelReservation(ActionEvent event){
		ReservationController rc = new ReservationController();
		rc.cancelReservation();
	}
	
	/**
	 * Invoke rentcontroller.dorent
	 * @param event
	 */
	@FXML
	public void rentVehicle(ActionEvent event){
		RentController rentControl = new RentController();
		rentControl.doRent();
	}
	
	/**
	 * Invoke Returncontroller
	 * @param event
	 */
	@FXML
	public void returnVehicle(ActionEvent event){
		ReturnController returnControl = new ReturnController();
		returnControl.doReturn();
	}
	
	/**
	 * Invoke Usercontroller.viewVehicleStatus method
	 * @param event
	 */
	@FXML
	public void viewVehicleStatus(ActionEvent event){
		Navigator.loadStackPane(Navigator.VEHICLE_STATUS);
	}
	
	/**
	 * This method is invoked when manager clicks Edit Customer Profile button
	 * Precondition: manager is logged in
	 * Postcondition: Edit customer profile stackpane is loaded
	 * @param event
	 */
	@FXML
	public void editCustomerProfile(ActionEvent event){
			UserController.page = 5;
			Navigator.loadStackPane(Navigator.EDITCUSTOMERPROFILEFXML);
	}
	
	@FXML
	public void showOverDueVehicles(ActionEvent event)
	{
		RentController.setSceneNumber(7);
		Navigator.loadStackPane(Navigator.OverDUEVEHICLES);
	}
	
	@FXML
	public void viewAllVehicles(ActionEvent event){
		ReportController.page=1;
		Navigator.loadStackPane(Navigator.OVERALLVEHICLELIST);
	}
	
	/**
	 * UserController.editProfile() method
	 * @param event
	 * @throws SQLException 
	 */
	@FXML
	public void editProfile(ActionEvent event) throws SQLException{
		UserController managerobjedit = new UserController();
		managerobjedit.editProfile(Navigator.getPhoneNumber());
		
	}
	
	/**
	 * load usercontroller.changePassword method
	 * @param event
	 */
	@FXML
	public void managerchangePassword(ActionEvent event){
		System.out.println("Loading Manager Change Password");
		UserController managerobjchange = new UserController();
		managerobjchange.changePassword();
	}
	
	@FXML
	public void home(ActionEvent event){
		Navigator.loadStackPane(Navigator.MANAGER_HOME);
	}
	
	@FXML
	public void logOut(ActionEvent event) throws IOException{
		Navigator.setManager(null);
		Navigator.setPhoneNumber(null);
		 FXMLLoader myLoader = new  FXMLLoader(getClass().getResource("/userManagementUI/LoginPage.fxml"));
	        Stage MainStage = new Stage();
	        Pane MainPagePane = (Pane)myLoader.load();
	        LoginController controller = (LoginController) myLoader.getController();
	        controller.SetStage(MainStage);
	        
	       // stage.setTitle("Login");
	        Scene myScene = new Scene(MainPagePane);        
	        MainStage.setScene(myScene);
	        MainStage.setTitle("SUPERRENT");
	        MainStage.setResizable(false);
	        MainStage.setWidth(605);
	        MainStage.setHeight(445);
	        MainStage.show();
	        managerStage.close();
	}
	
}
